﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace MCromwell.StaffIntranet.Task.Extensions
{
    public static class ReflectionExtensions
    {
        public static T GetFirstCustomAttribute<T>(this MemberInfo memberInfo, Type Matching, bool UseInheritance) where T : Attribute
        {
            if (memberInfo == null)
                return default(T);

            object[] foundAttributes = memberInfo.GetCustomAttributes(Matching, UseInheritance);
            if (foundAttributes.Length > 0)
                return foundAttributes[0] as T;
            else
                return default(T);
        }

    }
}
